package com.smcdd.cdb.dbo.cdb_dbo.ui.activity;


import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.event.ShopType;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.AddMenDianPresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.MenDianPresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.IMenDianAc;
import com.smcdd.cdb.dbo.cdb_dbo.ui.adapter.ShopPagerAdapter;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseFragmentActivity;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseFragmentFragment;
import com.smcdd.cdb.dbo.cdb_dbo.ui.fragment.FragmentFactory;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.MenDianPopup;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.NoScrollViewPager;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.PagePopup;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：Administrator on 2017/6/19 17:06
 * 邮箱：zhanghuaiha@gmail.com
 * 门店管理
 */

public class MenDianActivity extends BaseFragmentActivity<IMenDianAc,MenDianPresenter> implements IMenDianAc{
    public TextView shop_map,shop_list,shop_wifi,shop_mima,shop_paper;
    private NoScrollViewPager mPager;
    public ImageView back,add;
    private List<BaseFragmentFragment> mFragmentList = new ArrayList<>();
    private MenDianPopup titlePopup;
    private MenDianPopup.OnItemOnClickListener onitemClick = (type0) -> {
//        EventBus.getDefault().post(new ShopType(type0));
    };
    public void initView() {
//        shop_map = (TextView) findViewById(R.id.shop_map);
        shop_list = (TextView) findViewById(R.id.shop_list);
        shop_wifi = (TextView) findViewById(R.id.shop_wifi);
        shop_mima = (TextView) findViewById(R.id.shop_mima);
        shop_paper = (TextView) findViewById(R.id.shop_paper);
        mPager = (NoScrollViewPager) findViewById(R.id.shop_viewpager);
        back = (ImageView) findViewById(R.id.shop_back);
        add = (ImageView) findViewById(R.id.shop_add);

    }

    @Override
    public void initData() {
        //initPopWindow();
        mFragmentList.add(FragmentFactory.getInstance().getMenDianListFragment());
//        mFragmentList.add(FragmentFactory.getInstance().getMenDianMapFragment());
        mPager.setAdapter(new ShopPagerAdapter(getSupportFragmentManager(),mFragmentList));
        shop_list.setSelected(true);
    }

    private void initPopWindow() {
        // 实例化标题栏弹窗
        titlePopup = new MenDianPopup(this, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        titlePopup.setItemOnClickListener(onitemClick);
    }

    public String getNot(){
        String not = getIntent().getStringExtra("not");
        return not;
    }

    @Override
    public void initListener() {

        back.setOnClickListener(v -> finish());
        add.setOnClickListener(v -> {
            jumpToActivity(AddMenDianActivity.class);
            finish();
        });
        shop_list.setOnClickListener(v -> {
            shop_list.setSelected(true);
            shop_wifi.setSelected(false);
            shop_mima.setSelected(false);
            shop_paper.setSelected(false);
            EventBus.getDefault().post(new ShopType("0"));
        });

        shop_wifi.setOnClickListener(v -> {
            shop_list.setSelected(false);
            shop_wifi.setSelected(true);
            shop_mima.setSelected(false);
            shop_paper.setSelected(false);
            EventBus.getDefault().post(new ShopType("1"));
        });

        shop_mima.setOnClickListener(v -> {
            shop_list.setSelected(false);
            shop_wifi.setSelected(false);
            shop_paper.setSelected(false);
            shop_mima.setSelected(true);
            EventBus.getDefault().post(new ShopType("4"));
        });

        shop_paper.setOnClickListener(v ->  {
            shop_list.setSelected(false);
            shop_wifi.setSelected(false);
            shop_paper.setSelected(true);
            shop_mima.setSelected(false);
            EventBus.getDefault().post(new ShopType("5"));
        });



//        shop_list.setOnClickListener(v -> mPager.setCurrentItem(0));
//        shop_map.setOnClickListener(v -> mPager.setCurrentItem(1));
        mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        shop_list.setSelected(true);
//                        shop_map.setSelected(false);

                       // sort.setVisibility(View.VISIBLE);
                        break;
                    case 1:
                        shop_list.setSelected(false);
//                        shop_map.setSelected(true);
                       // sort.setVisibility(View.INVISIBLE);
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected MenDianPresenter createPresenter() {
        return new MenDianPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_mendian;
    }


}
